#!/usr/bin/python3
# -*- coding:utf-8 -*-
# @Author    :Timo

import time
import asyncio
import aiohttp


def task_up_time(func):
    def wrapper(*args, **kwargs):
        print("开始执行---------")
        now = time.time()
        result = func(*args, **kwargs)
        using = (time.time() - now) * 1000
        print(f"结束执行, 消耗时间为: {using}ms")
        return result

    return wrapper


async def request_sync(url):
    async with aiohttp.ClientSession() as session:
        async with session.get(url) as resp:
            pass


@task_up_time
def run():
    url = "https://www.baidu.com"
    tasks = [asyncio.ensure_future(request_sync(url)) for i in range(0, 50)]
    loop = asyncio.get_event_loop()
    tasks = asyncio.gather(*tasks)
    loop.run_until_complete(tasks)
    loop.close()


if __name__ == '__main__':
    run()
